package ua.kpi.JavaTraning5;

import junit.framework.Assert;
import org.junit.Test;

import static ua.kpi.JavaTraning5.LongDivision.*;

/**
 * This class includes methods for testing LongDivision class.
 *
 * @author Vitaliy Vasylenko <apa4i007@gmail.com>
 * @version 1.1
 * @since 2013-05-22
 */
public class LongDivisionTest {
    @Test
    public void testReadValue() throws Exception {

    }

    @Test
    public void testIsNotNull() throws Exception {
        Assert.assertEquals(isNotNull(4), true);
        Assert.assertEquals(isNotNull(-1), false);
        Assert.assertEquals(isNotNull(0), false);
    }

    @Test
    public void testDivide() throws Exception {
        int[] resultOfDivide = divide(777, 6);
        int[] etalonResult = {1,2,9};
        Assert.assertEquals(resultOfDivide.length,etalonResult.length);
        for (int i = 0; i < resultOfDivide.length; i++) {
            Assert.assertEquals(resultOfDivide[i],etalonResult[i]);
        }
    }

    @Test
    public void testGetMainPartFromDivider() throws Exception {
        Assert.assertEquals(getMainPartFromDivider(1,"2",6),2);
        Assert.assertEquals(getMainPartFromDivider(0,"7",6),1);
    }

    @Test
    public void testGetLastFromDivided() throws Exception {
        Assert.assertEquals(getLastFromDivided(0,"8",2,3),2);
        Assert.assertEquals(getLastFromDivided(0,"9",2,3),3);
        Assert.assertNotSame(getLastFromDivided(0,"9",2,3),8);
    }

    @Test
    public void testCalculateLongDivisionStepByStep() throws Exception {
        Assert.assertEquals(calculateLongDivisionStepByStep(777,6).length(),15);
        Assert.assertEquals(calculateLongDivisionStepByStep(123,7).length(),14);
    }

    @Test
    public void testPrintGraphicsForDivision() throws Exception {
        Assert.assertEquals("|_" + 777 + "_" + "\n" + "" + "    " + 129,printGraphicsForDivision(777,129));
        Assert.assertNotSame("|_" + 777 + "_+" + "\n" + "" + "    " + 129,printGraphicsForDivision(777,129));
    }
}
